<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models\Projects;

use Carbon\Carbon;
use App\Models\Eloquent;
use App\Models\Meimei\Traits\SignOssUrlTrait;
use App\Models\Meimei\Traits\ExplodeTrait;

/**
 * Class QtpProject
 *
 * @property int $id
 * @property int $cate_id
 * @property string $icon
 * @property string $name
 * @property string $remark
 * @property string $note
 * @property string $tags
 * @property string $created_adminer
 * @property string $updated_adminer
 * @property int $sort
 * @property int $enable
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 *
 * @package App\Models
 */
class Project extends Eloquent
{
    use ExplodeTrait;
    use SignOssUrlTrait;
    protected $explode_img = ['icon']; // 单图
    protected $explode = ['tags'];

	protected $table = 'projects';

	protected $casts = [
		'cate_id' => 'int',
		'sort' => 'int',
		'enable' => 'int'
	];

	protected $fillable = [
		'cate_id',
		'icon',
		'name',
		'remark',
		'note',
		'tags',
		'created_adminer',
		'updated_adminer',
		'sort',
		'enable'
	];

    public function label()
    {
        $this->cate_name = ProjectCate::find($this->cate_id)->name ?? '';
        $this->product_num = Product::where('project_id', $this->id)->count();
        return $this;
    }

    public static $fillables = [
        'cate_id' => '分类',
        'icon' => '项目图标',
        'name' => '项目名称',
        'remark' => '项目描述',
        'note' => '项目备注',
        'tags' => '项目标签',
        'created_adminer' => '项目创建人',
        'updated_adminer' => '项目更新人',
        'sort' => '项目排序',
        'enable' => '项目状态'
    ];
}
